package com.aiti.lulian.controller;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardContractCollaboratorDto;
import com.aiti.lulian.entity.CardContractCollaborator;
import com.aiti.lulian.service.CardContractCollaboratorService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@Api(tags = "合同协作人控制层")
@RestController
@RequestMapping("contract/collaborator")
public class CardContractCollaboratorController extends WebController {


    @Autowired
    private CardContractCollaboratorService contractCollaboratorService;




    @ApiOperation("新增合同协作人")
    @PostMapping("deal")
    public Message dealCollaborator(@RequestBody CardContractCollaboratorDto dto) {


        return contractCollaboratorService.dealCollaborator(dto);
    }

    @ApiOperation("展示所选合同的协作人")
    @PostMapping("collaboratorList")
    public Message collaboratorList(@RequestBody CardContractCollaboratorDto dto) {
        List<String> contractIdList = dto.getIdList();
        List<CardContractCollaborator> collaboratorList = contractCollaboratorService.list(new LambdaQueryWrapper<CardContractCollaborator>().select(CardContractCollaborator::getUserId,CardContractCollaborator::getUserName).in(CardContractCollaborator::getRelateId,contractIdList).groupBy(CardContractCollaborator::getUserId).groupBy(CardContractCollaborator::getUserName));
        return Message.success(collaboratorList);

    }




}